package com.note.servlet.view;

import com.alibaba.fastjson.JSON;
import com.note.pojo.Note;
import com.note.service.note.noteService;
import com.note.service.note.noteServiceImpl;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

public class read extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        int noteId = Integer.parseInt(req.getParameter("noteId"));
        noteService n = new noteServiceImpl();
        HashMap edit = n.edit(noteId);
        Note note = (Note) edit.get("note");
        PrintWriter out = resp.getWriter();
        String jsonNote = JSON.toJSONString(note);
        out.write(jsonNote);
        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
